/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.ac.cput.DesignPatterns.behavioral.Observer;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author Nashief
 */
public class WeatherStation implements WeatherSubject{

    Set<WeatherObserver> weatherObservers;
    int tempreture;
    
    public WeatherStation(int tempreture){
    weatherObservers= new HashSet<WeatherObserver>();
    this.tempreture=tempreture;
    }
    
    @Override
    public void addObserver(WeatherObserver weatherObserver) {
       weatherObservers.add(weatherObserver);
    }

    @Override
    public void removeObserver(WeatherObserver weatherObserver) {
       weatherObservers.remove(weatherObserver);
    }

    @Override
    public void doNotify() {
        Iterator<WeatherObserver> it= weatherObservers.iterator();
        while(it.hasNext()){
        WeatherObserver weatherObserver=it.next();
         weatherObserver.doUpdate(tempreture);
        }
    }
    public void setTempreture(int newTempreture){
    System.out.println("\n Weather station tempreture to"+newTempreture);
    tempreture= newTempreture;
    doNotify();
    }
    
}
